package main;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerListModel;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Frame extends javax.swing.JFrame {
	Manager manager;
	private JButton settings;
	private JButton jButton1;	//Exit program
	private JButton clear;		//Clear screen
	private JTextField gravNum;	//Current gravity
	private JLabel gravLabel;	//Display current gravity
	public JSlider gravity;		//Change gravity
	JLabel Currently;			//Display current activity
	private JButton action;		//Begin physics simulation
	private JButton erase;		//Enter drawing mode
	private JButton drawButton;	//Enter erasing mode
	private PropertiesWindow properties;
	public Frame() {
		super();
		initGUI();
	}
	
	public void setPropertiesWindow(PropertiesWindow properties){
		this.properties = properties;
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setUndecorated(true);
			this.setResizable(false);
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Quit");
				jButton1.setBounds(746, 12, 112, 21);
				jButton1.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						jButton1MouseClicked(evt);
					}
				});
			}
			{
				drawButton = new JButton();
				getContentPane().add(drawButton);
				drawButton.setText("Draw");
				drawButton.setBounds(746, 38, 112, 21);
				drawButton.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						drawButtonMouseClicked(evt);
					}
				});
			}
			{
				clear = new JButton();
				getContentPane().add(clear);
				clear.setText("Clear");
				clear.setBounds(746, 122, 109, 21);
				clear.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						clearMouseClicked(evt);
					}
				});
			}
			{
				erase = new JButton();
				getContentPane().add(erase);
				erase.setText("Erase");
				erase.setBounds(746, 96, 109, 21);
				erase.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						eraseMouseClicked(evt);
					}
				});
			}
			{
				action = new JButton();
				getContentPane().add(action);
				action.setText("Move!!!");
				action.setBounds(746, 148, 109, 21);
				action.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						actionMouseClicked(evt);
					}
				});
			}
			{
				Currently = new JLabel();
				getContentPane().add(Currently);
				Currently.setText("Drawing");
				Currently.setBounds(776, 486, 79, 33);
				Currently.setFont(new java.awt.Font("Chancery Uralic",1,16));
			}
			{
				gravity = new JSlider();
				getContentPane().add(gravity);
				gravity.setBounds(88, 507, 200, 16);
				gravity.setValue(70);
				gravity.addMouseMotionListener(new MouseMotionAdapter() {
					public void mouseDragged(MouseEvent evt) {
						gravityMouseDragged(evt);
					}
				});
			}
			{
				gravLabel = new JLabel();
				getContentPane().add(gravLabel);
				gravLabel.setText("Gravity:");
				gravLabel.setBounds(7, 507, 113, 14);
			}
			{
				gravNum = new JTextField();
				getContentPane().add(gravNum);
				gravNum.setText("20");
				gravNum.setBounds(288, 504, 26, 21);
				gravNum.setEditable(false);
			}
			{
				settings = new JButton();
				getContentPane().add(settings);
				settings.setText("Settings");
				settings.setBounds(758, 64, 100, 21);
				settings.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						settingsMouseClicked(evt);
					}
				});
			}
			this.addMouseListener(new MouseAdapter() {
				public void mouseReleased(MouseEvent evt) {
					thisMouseReleased(evt);
				}
				public void mousePressed(MouseEvent evt) {
					thisMousePressed(evt);
				}
			});
			pack();
			this.setSize(876, 550);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void setManager(Manager m){
		manager = m;
	}
	private void thisMousePressed(MouseEvent evt) {
		manager.click();	//Tell manager that event has occurred
	}
	
	private void thisMouseReleased(MouseEvent evt) {
		manager.release();	//Tell manager that event is no longer occurring
	}
	
	private void jButton1MouseClicked(MouseEvent evt) {
		System.exit(0);	//Quit;
	}
	
	private void drawButtonMouseClicked(MouseEvent evt) {
		manager.draw = true;	//Tell manager that mode is drawing
		manager.erase = false;	//Not erasing
		Currently.setText("Drawing");	//Adjust status text in lower right corner
	}
	
	private void clearMouseClicked(MouseEvent evt) {
		manager.clear();	//Clear graphics panel
		Currently.setText("Drawing");
	}
	
	private void eraseMouseClicked(MouseEvent evt) {
		manager.draw = true;	//Drawing
		manager.erase = true;	//and Erasing
		Currently.setText("Erasing");
	}
	
	private void actionMouseClicked(MouseEvent evt) {
		manager.draw = false;	//Not drawing, so physics are activated
		manager.erase = false;
		Currently.setText("Moving");
	}
	
	private void gravityMouseReleased(MouseEvent evt) {
		gravNum.setText(Integer.toString(gravity.getValue()-50));
	}
	
	private void gravityMouseDragged(MouseEvent evt) {
		gravNum.setText(Integer.toString(gravity.getValue()-50));
	}
	
	private void settingsMouseClicked(MouseEvent evt) {
		properties.setVisible(true);
	}
	
	private void thisFocusGained(FocusEvent evt) {
		properties.setVisible(true);
	}
	
	private void thisFocusLost(FocusEvent evt) {
		properties.setVisible(false);
	}

}
